/**
 * Created by ChrisBi on 16/7/24.
 */
//audio left
function PlayAudioLeft(idx){
    var voice = document.getElementById("voice" + idx);
    var img = document.getElementById("PlayPause" + idx);
    img.onclick = function(){
        if (voice.paused){
            voice.play();
        } else{
            voice.pause();
        }
    }
    voice.addEventListener("play", function (e) {
        img.src = "icon/voice_left_click.gif";
    }, false);
    voice.addEventListener("pause", function (e) {
        img.src = "icon/voice_left.png";
    }, false);

}


//audio right
function PlayAudioRight(idx){
    var voiceR = document.getElementById("voiceMe" + idx);
    var imgR = document.getElementById("PlayPauseMe" + idx);
    imgR.onclick = function(){
        if (voiceR.paused){
            voiceR.play();
        } else{
            voiceR.pause();
        }
    }
    voiceR.addEventListener("play", function (e) {
        imgR.src = "icon/voice_right_click.gif";
    }, false);
    voiceR.addEventListener("pause", function (e) {
        imgR.src = "icon/voice_right.png";
    }, false);
}

/**
 * Created by Rison on 22/1/29.
 */
var MsgDef = {
    text:1,                 //文字
    normalImg: 3,           //图片
    voice:34,               //语音
    recall:38,              //撤回
    contact:42,             //名片
    video1:43,              //视频
    playImg:47,             //表情包
    gps:48,                 //位置消息
    extend:49,              //扩展消息或卡片消息：文件，分析，位置共享，小程序，红包，转账等等
    videoCall:50,           //视频聊天
    video2:62,              //同43，视频
    system:10000,           //系统消息
};

var WeChat = {
    isTextMsg:      function(item) {
        return item.m_uiMessageType === MsgDef.text;
    },
    isEmojiMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.playImg;
    },
    getEmojiUrl:    function(item) {
        if (typeof(item.m_nsContent) === 'string')
            return item.m_nsContent;
        else if (item.m_nsContent.msg && item.m_nsContent.msg.emoji)
            return item.m_nsContent.msg.emoji.cdnurl;
        return "";
    },
    isImageMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.normalImg;
    },
    isVoiceMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.voice;
    },
    isVideoMsg:     function(item) {
        return item.m_uiMessageType === MsgDef.video1
         || item.m_uiMessageType === MsgDef.video2;
    },
    isVideoChat:    function(item) {
        return item.m_uiMessageType === MsgDef.videoCall;
    },
    isFileMsg:      function(item) {
        if (item.m_uiMessageType != MsgDef.extend) return false;
        return item.m_nsContent && item.m_nsContent.msg && item.m_nsContent.msg.appmsg && item.m_nsContent.msg.appmsg.type == 6;
    },
    isShareLink:    function(item) {
        if (item.m_uiMessageType != MsgDef.extend) return false;
        if (item.m_nsContent && item.m_nsContent.msg && item.m_nsContent.msg.appmsg) {
            let subType = item.m_nsContent.msg.appmsg.type;
            //TODO, 3是音乐分享
            return subType==3 || subType==4 || subType==5 || subType==7;
        }
    },
    isLocationMsg:  function(item) {
        return item.m_uiMessageType === MsgDef.gps;
    },
    isContactMsg:   function(item) {
        return item.m_uiMessageType == MsgDef.contact;
    },
    isMiniProgram:  function(item) {
        if (item.m_uiMessageType != MsgDef.extend) return false;
        if (item.m_nsContent && item.m_nsContent.msg && item.m_nsContent.msg.appmsg) {
            let subType = item.m_nsContent.msg.appmsg.type;
            return subType==33 || subType==36;
        }
        return false;
    }
};